package com.redis;

import com.redis.procuder.RedisService;
import com.redis.tools.RedisTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;

@RestController
@SpringBootApplication
public class RedisApplication implements CommandLineRunner{

	@Autowired
	private StringRedisTemplate stringRedisTemplate;

	@Autowired
	private RedisService redisService;

	public static void main(String[] args) {
		SpringApplication.run(RedisApplication.class, args);
	}

	@RequestMapping("test")
	public void test(){
		redisService.sendChannelMess("order1","wewewew");
	}

	@RequestMapping("lpush")
	public void lpush(){
		RedisTools.lPush(stringRedisTemplate,"reg", UUID.randomUUID().toString().replaceAll("-",""));
	}

	@Override
	public void run(String... strings) throws Exception {
		while (true){
			List<String> list = new ArrayList<>();
			for (int i = 0; i < 100; i++) {
				String s = RedisTools.rpop(stringRedisTemplate,"reg");
				if(s==null){
					break;
				}
				list.add(s);
			}
			//发送短信
			//修改短信发送状态成功或失败
			System.out.println(list);
			System.out.println("一分钟读取一次:"+ LocalDateTime.now());
			Thread.sleep(60000);
		}
	}
}
